package com.uu;

import com.uu.config.ConfigDemo;
import com.uu.config.DataConfig;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@EnableConfigurationProperties
@Import(ConfigDemo.class)
@EnableTransactionManagement(proxyTargetClass = true)
public class BootApplication implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(BootApplication.class);
        System.out.println(applicationContext.getAutowireCapableBeanFactory().getBean(ConfigDemo.class));
        DataConfig dataConfig = applicationContext.getAutowireCapableBeanFactory().getBean(DataConfig.class);
        System.out.println(dataConfig.getLength());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
